# -*- coding: utf-8 -*-

# Scrapy settings for digkey_icnet project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     http://doc.scrapy.org/en/latest/topics/settings.html
#     http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
#     http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'digkey_icnet'

SPIDER_MODULES = ['digkey_icnet.spiders']
NEWSPIDER_MODULE = 'digkey_icnet.spiders'

MYSQL_URI="localhost"
MYSQL_USER="root"
MYSQL_PSW="mysql01216016"
MYSQL_DB="digikey_icnet"

# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'digkey_icnet (+http://www.yourdomain.com)'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 1
#开启10个spider
# #将调度器更改为scrapy-redis
# SCHEDULER = "scrapy_redis.scheduler.Scheduler"
# #替换成scrapy-redis去重方法
# DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDupeFilter"
# #远程主机的redis调取队列
# REDIS_URL = 'redis://root:@127.0.0.1:6379'  # 帐号：密码@主机ip：端口
# Configure a delay for requests for the same website (default: 0)
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
# DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
#COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False

# Override the default request headers:
# DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'zh-CN,zh;q=0.9',
#   'Cache-Control': 'max-age=0',
#   'Connection': 'keep-alive',
#   'Host': 'www.digikey.com.cn',
#   'Upgrade-Insecure-Requests': '1',
#   'Referer:https':'//www.digikey.com.cn/products/zh/%E4%BC%A0%E6%84%9F%E5%99%A8-%E5%8F%98%E9%80%81%E5%99%A8/%E4%B8%93%E7%94%A8%E4%BC%A0%E6%84%9F%E5%99%A8/561?pageNumber=1',
#   'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36',
# }

# Enable or disable spider middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
#    'digkey_icnet.middlewares.DigkeyIcnetSpiderMiddleware': 543,
# }

# Enable or disable downloader middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
   'digkey_icnet.middlewares.HttpErrorMiddleware': 545,
  #'digkey_icnet.middlewares.CustomFaillogMiddleware': 544,
}
#SCHEDULER_PERSIST = True
# Enable or disable extensions
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
   'digkey_icnet.pipelines.DigkeyIcnetPipeline': 300,
}
HTTPERROR_ALLOWED_CODES = [403]#上面报的是403，就把403加入。
DOWNLOAD_TIMEOUT = 10
RETRY_TIMES = 10
# Enable and configure the AutoThrottle extension (disabled by default)
# See http://doc.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'

